package com.cy.sc.service;

import com.cy.sc.dao.StaffDao;
import com.cy.sc.pojo.Staff;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StaffServiceImpl implements IStaffService {
    @Autowired
    private StaffDao staffDao;

    @Override
    public boolean addStaff(Staff Staff) {
        return staffDao.addStaff(Staff);
    }
    @CacheResult(cacheKeyMethod = "getCacheKey")//使用缓存
    @HystrixCommand(commandKey = "getCacheKey")
    @Override
    public Staff getStaffById(long id) {
        System.out.println("Executed StaffServiceImpl.getStaffById!");
        return staffDao.getStaffById(id);
    }

    @Override
    public List<Staff> getStaffAll() {
        return staffDao.getStaffAll();
    }

    //缓存方案 生成缓存key
    private String getCacheKey(long id) {
        return id + "";

    }

}
